﻿using System;
using FreeSwitch.EventSocket.Parser;

namespace FreeSwitch.EventSocket.Commands
{
	/// <summary>
	/// Subscribes on events by sending "event" command to FreeSwitch
	/// </summary>
	class Subscribe : ICommand
	{
		private readonly string[] _eventNames;

		public Subscribe(params string[] eventNames)
		{
			_eventNames = eventNames;
		}

		/// <summary>
		/// Parses a reply sent from FreeSwitch for a command.
		/// </summary>
		/// <param name="msg"></param>
		/// <returns></returns>
		public ICommandReply ParseReply(ParsedMessage msg)
		{
			return CommandReply.Parse(msg);
		}

		/// <summary>
		/// Generate a string that can be sent to FreeSWITCH
		/// </summary>
		/// <returns>String that FreeSWITCH can interpret as a command.</returns>
		public string ToCommandString()
		{
			return ToString();
		}

		public override string ToString()
		{
			return "event plain " + string.Join(" ", _eventNames) + "\n";
		}
	}
}
